package com.zb.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.zb.springcloud.feign.FeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
@Slf4j
@RestController
//@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod", commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2500")
//    })
public class OrderHystrixController {
    @Resource
    private FeignService feignService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_Ok(@PathVariable("id") Integer id){
        return feignService.paymentInfo_Ok(id);
    }

    //    @HystrixCommand
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
//    @HystrixCommand(fallbackMethod = "paymentTimeOutFallBackMethod", commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2500")
//    })
    public String paymentInfo_Timeout(@PathVariable("id") Integer id){
        return feignService.paymentInfo_Timeout(id);
    }

    public String paymentTimeOutFallBackMethod(@PathVariable("id") Integer id){
        return "我是消费者8002， 对方提供服务系统繁忙，请稍后再试或者自己运行错误检查自己， (；′⌒`)";
    }
//    下面试全局fallback

    public String payment_Global_FallbackMethod(){
        return "Global异常信息处理， 清扫后再试  (；′⌒`)";
    }

    @GetMapping("/payment/circuit/{id}")
    String paymentCircuitBreaker(@PathVariable("id") Integer id){
        return feignService.paymentCircuitBreaker(id);
    }
}
